//---------------------------------------------------------
// Copyright (c) 2021,jiansan All rights reserved.
//
// 文件名称：Drv_as8510.h
// 文件标识：
// 文件摘要：
//
// 当前版本：V1.0
// 作    者：zhangjianzhou
// 完成时间：2021.05.19
//---------------------------------------------------------

#ifndef  __AS8510_H
#define  __AS8510_H	
#include "main.h"

//#define GET_VOLTAGE_TYPE    0X00   //读取电压值
//#define GET_ETR_TYPE        0X40   //读取ETR温度
//#define GET_ETS_TYPE        0X80   //读取ETS温度
//#define GET_INT_TYPE        0XC0   //读取内部温度

typedef enum {
	GET_VOLTAGE_TYPE = 0X00,   //读取电压值
	GET_ETR_TYPE     = 0X40,   //读取ETR温度
	GET_ETS_TYPE     = 0X80,   //读取ETS温度
	GET_INT_TYPE     = 0XC0,   //读取内部温度
}AchCtlRge_e;

typedef enum {
	Gain_1=1, 
	Gain_5=5,   
	Gain_25=25,   
	Gain_40=40,   
	Gain_100=100,
}Gain_e;



////////////////////////////////////////////////////////////////////////////////// 
//寄存器
//Data Access Registers
#define DREG_I1        0X00
#define DREG_I2        0X01
#define DREG_V1        0X02
#define DREG_V2        0X03

//Status Registers
#define DSTATUS_REG    0X04

//Digital Signal Path Control Registers for Current Channel
#define DEC_REG_R1_I   0X05
#define DEC_REG_R2_I   0X06
#define FIR_CTL_REG_I  0X07

//Digital Control Registers
#define CLK_REG  	   0X08
#define RESET_REG  	   0X09
#define MOD_CTL_REG    0X0A
#define MOD_Ta_REG1    0X0B
#define MOD_Ta_REG2    0X0C
#define MOD_ITH_REG1   0X0D  //Current Threshold Register  MSB bits
#define MOD_ITH_REG2   0X0E  //Current Threshold Register  LSB bits
#define MOD_TMC_REG1   0X0F  //TMC Control Register  MSB bits
#define MOD_TMC_REG2   0X10  //TMC Control Register  LSB bits
#define NOM_ITH_REG1   0X11  //Eight MSB bits of NOM2 current threshold register
#define NOM_ITH_REG2   0X12  //Eight LSB bits of NOM2 current threshold register

//Analog Control Registers
#define PGA_CTL_REG    0X13  //PGA Control Registers  Setting of Gain PGA.
#define PD_CTL_REG_1   0X14  //Power Down Control Register
#define PD_CTL_REG_2   0X15  //Power Down Control Register
#define PD_CTL_REG_3   0X16  //Power Down Control Register
#define ACH_CTL_REG    0X17  //Analog Channel Selection Register
#define ISC_CTL_REG    0X18  //Current Source Setting Register
#define OTP_EN_REG     0X19  

#define STATUS_REG_2   0X44  //Status indicating data saturation in Current/Voltage channel 

//Digital Signal path control registers for Voltage Channel
#define DEC_REG_R1_V   0X45  
#define DEC_REG_R2_V   0X46  
#define FIR_CTL_REG_V  0X47 


#define GET_ETS_PTC 		CD74HC4051_U1_A0

#define GET_ETR_CON1 		CD74HC4051_U2_A0

#define GET_VOLTAGE_Um 		CD74HC4051_U1_A1
#define GET_VOLTAGE_Uj  	CD74HC4051_U1_A2

//#define AS8510_SPI_SCS			PBout(3)     /* PA4推挽输出  CS  */
//typedef unsigned char u8;
//typedef unsigned int u16;
void Drv_As8510Install(void);
void Drv_As8510Init(void);
void Drv_As8510WriteReg(uint8_t uiWriteAddr,uint8_t ucValue);
 uint8_t Drv_As8510ReadReg(uint8_t uiReadAddr);
void Drv_CurrentGainSet(Gain_e Gain);
 uint8_t SPI_READ(uint8_t Txdata);
 void delay_us(unsigned char a);
uint16_t ReadTemp(void);
uint16_t Drv_As8510ReadCurrent(uint16_t *fCurrent);
float Kal_Man(float res);
void SwitchCNum(uint8_t num);
typedef struct{
   float kg;
   float Q;
   float R;
   float x_pre;
   float p_pre;
   float p_last;
   float p_now;
   float x_now;
   float x_last;
   float x_pid;
}KALMAN;



#endif




